// task_transaction_record_detail_page.dart
import 'package:flutter/material.dart';
import 'task_transaction_record_page.dart';

class TaskTransactionRecordDetailPage extends StatefulWidget {
  final TaskRecordType type;

  const TaskTransactionRecordDetailPage({
    Key? key,
    required this.type,
  }) : super(key: key);

  @override
  State<TaskTransactionRecordDetailPage> createState() =>
      _TaskTransactionRecordDetailPageState();
}

class _TaskTransactionRecordDetailPageState
    extends State<TaskTransactionRecordDetailPage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final List<String> _tabTitles = ['收入', '支出'];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _tabTitles.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          widget.type == TaskRecordType.cash ? '现金收支明细' : '金币收支明细',
        ),
        backgroundColor: Colors.white,
        foregroundColor: Colors.black,
        elevation: 0.5,
        bottom: TabBar(
          controller: _tabController,
          tabs: _tabTitles.map((title) => Tab(text: title)).toList(),
          labelColor: const Color(0xFFFF4974), // ThemeColor
          unselectedLabelColor: const Color(0xFF666666), // TextColor
          labelStyle: const TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.w600,
          ),
          unselectedLabelStyle: const TextStyle(
            fontSize: 14,
            fontWeight: FontWeight.w500,
          ),
          indicator: const UnderlineTabIndicator(
            borderSide: BorderSide(
              width: 4,
              color: Color(0xFFFF4974),
            ),
            insets: EdgeInsets.symmetric(horizontal: 30),
          ),
          indicatorSize: TabBarIndicatorSize.label,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: _tabTitles.asMap().entries.map((entry) {
          final index = entry.key;
          return TaskTransactionRecordPage(
            type: widget.type,
            category: index,
          );
        }).toList(),
      ),
    );
  }
}